NODE_ADDRESS=${1:-"172.19.47.172"}
HOSTNAME_OVERRIDE=${2:-"k8s-node-1"}
CLUSTER_CIDR=${3:-"10.254.0.0/16"}

KUBE_KUBECONFIG_DIR="/opt/kubernetes/kubeconfig"

cat <<EOF >/opt/kubernetes/cfg/kube-proxy
KUBE_LOGTOSTDERR="true"
KUBE_LOG_LEVEL="4"
NODE_BIND_ADDRESS="${NODE_ADDRESS}"
NODE_HOSTNAME="${HOSTNAME_OVERRIDE}"
#KUBE_MASTER="--master=http://${MASTER_ADDRESS}:8080"
NODE_KUBECONFIG="${KUBE_KUBECONFIG_DIR}/kube-proxy.kubeconfig"
KUBE_CLUSTER_CIDR="${CLUSTER_CIDR}"
EOF

cat <<EOF >/usr/lib/systemd/system/kube-proxy.service
[Unit]
Description=Kubernetes Proxy
After=network.target
[Service]
EnvironmentFile=-/opt/kubernetes/cfg/kube-proxy
ExecStart=/opt/kubernetes/bin/kube-proxy \
--logtostderr=\${KUBE_LOGTOSTDERR} \
--v=\${KUBE_LOG_LEVEL} \
--bind-address=\${NODE_BIND_ADDRESS} \
--hostname-override=\${NODE_HOSTNAME} \
--kubeconfig=\${NODE_KUBECONFIG} \
--cluster-cidr=\${KUBE_CLUSTER_CIDR}

Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable kube-proxy
systemctl restart kube-proxy
systemctl status kube-proxy

echo -e "\033[42;37m==kube-proxy配置完成===============================================================================\033[0m"
